/*
	Copyright 2006, 2007, 2008, 2009, 2010 Bastiaan Grutters
    
    This file is part of Ages of Strife website.

    Ages of Strife website is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Ages of Strife website is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Ages of Strife website.  If not, see <http://www.gnu.org/licenses/>.
 */
var myPanel;

function imageOverlayInit() {
	var elements = YAHOO.util.Dom.getElementsByClassName( 'image-overlay', 'a' );
	for( i in elements ) {
		YAHOO.util.Event.addListener( elements[i], 'click', imageOverlay );
	}
	
	myPanel = new YAHOO.widget.Panel( "image-overlay-panel", { 
		visible: false,  
		draggable: false } );
	myPanel.cfg.setProperty( "underlay", "shadow" ); 
	//myPanel.cfg.setProperty( "modal", true ); 
	//myPanel.cfg.setProperty( "close", true ); 
	myPanel.cfg.setProperty( "constraintoviewport", true ); 
	//myPanel.cfg.setProperty( "fixedcenter", true ); 
	myPanel.cfg.setProperty( "iframe", true ); 
	myPanel.cfg.setProperty( "close", true ); 
	myPanel.cfg.setProperty( "y", 60 ); 
	myPanel.cfg.setProperty( "x", 60 ); 
	myPanel.cfg.setProperty( "effect", 
		{ effect: YAHOO.widget.ContainerEffect.FADE, duration: 0.25 }
//		  { effect: YAHOO.widget.ContainerEffect.SLIDE, duration: 0.25 }
		 );
}

var imageOverlay = function( event ) {
	var link = this;
	if( link.childNodes.length > 0 ) {
		var smallImg = link.childNodes[0];
		myPanel.setHeader( link.title );
		var img = document.createElement( 'img' );
		img.setAttribute( 'src', smallImg.getAttribute( 'src' ).replace( '-thumbnail', '' ) );
		myPanel.setBody( img );
		myPanel.show();
		YAHOO.util.Event.addListener( img, 'click', imageOverlayClose );
	}
}

var imageOverlayClose = function( event ) {
	myPanel.hide();
}

YAHOO.util.Event.addListener( window, 'load', imageOverlayInit );